package net.coding.li709.materialrefresher.keys;

import lombok.Getter;
import lombok.ToString;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.data.DataContainer;
import org.spongepowered.api.data.manipulator.immutable.common.AbstractImmutableData;
import org.spongepowered.api.data.value.immutable.ImmutableValue;

@Getter
@ToString
public class ImmutableFlanData extends AbstractImmutableData<ImmutableFlanData, FlanData> {

    private boolean isSpawn;

    private String spawnName;

    public ImmutableFlanData(boolean isSpawn,String spawnName) {
        this.isSpawn = isSpawn;
        this.spawnName=spawnName;
    }

    public ImmutableValue<Boolean> createIsSpawn() {
        return Sponge.getRegistry().getValueFactory().createValue(FlanKeys.IS_SPAWN, false, this.isSpawn).asImmutable();
    }

    public ImmutableValue<String> createSpawnName() {
        return Sponge.getRegistry().getValueFactory().createValue(FlanKeys.SPAWN_NAME, "", this.spawnName).asImmutable();
    }

    @Override
    protected void registerGetters() {
        registerFieldGetter(FlanKeys.IS_SPAWN, this::isSpawn);
        registerKeyValue(FlanKeys.IS_SPAWN, this::createIsSpawn);

        registerFieldGetter(FlanKeys.SPAWN_NAME, this::getSpawnName);
        registerKeyValue(FlanKeys.SPAWN_NAME, this::createSpawnName);
    }

    @Override
    public FlanData asMutable() {
        return new FlanData(isSpawn,spawnName);
    }

    @Override
    public int getContentVersion() {
        return 1;
    }

    @Override
    public DataContainer toContainer() {
        DataContainer dataContainer = DataContainer.createNew();
        return dataContainer.set(FlanKeys.IS_SPAWN, this.isSpawn)
                .set(FlanKeys.SPAWN_NAME,this.spawnName);
    }
}
